const {BaseService} = require('../../basic.js')
const {
	TeacherModel
} = require('dx-func-entity')
const _ = require('underscore');
// const {
// 	buildMenus
// } = require('../util/util.js')

module.exports = class Teachers extends BaseService {
	constructor(ctx) {
		super(ctx);
		this.entity = TeacherModel;		
	}
	company() {
	    //  hasOne('表名称','外键名','主键名')，绑定字段到主数据
		return this.hasOne('human-company', 'company_id', '_id').bindField({
			company_name: 'name',
		});
	}
	school() {
		return this.hasOne('human-company', 'school_id', '_id').bindField({
			school_name: 'name'
		});
	}
	findByIds(_ids){
		return this.where('_id','IN',_ids).field('name,school,school_id').limit(1000).select();
	}
	async findByNames(names=[]){
		const list = await this.where({name:['in',names]}).field('name,school,school_id').limit(1000).select();
		if(list.length==1000){
			const lst2 = await this.where({name:['in',names]}).skip(1000).field('name,school,school_id').limit(1000).select();
			list.push(...lst2);
		}
		return list;
	}
	async getTeacher({_id}){
		if(!_id){
			return this.$dx.error('导师 ID 不能为空');
		}
		const teacher = await this.where({_id}).find();
		const where = {
			'company_list.teacher':['contain',_id]
		};
		const talent = await this.$dx.service.talent.where(where).with(['company']).limit(1000).select();
		teacher.student = talent;
		return teacher;
	}
}
